<template>
	<s-layout title="快递查询" class="query-wrap">
		<view class="head-box">
			<view class="search-box">
				<view class="search-content">
					<text class="search-icon cicon-search-line"></text>
					<input class="search-input" type="text" placeholder="请输入查询单号" />
					<uni-icons type="scan" size="28" color="#c1c1c1"></uni-icons>
				</view>
			</view>
			<view class="tabs-box">
				<view
					class="tab"
					:class="{active: item.type == current}"
					v-for="(item, index) in tabs"
					:key="item.title"
					@click="onClick(item.type)"
				>
					{{ item.title }}({{item.number}})
				</view>
			</view>
		</view>
		<view class="container">
			<view v-for="item in list" :key="item.id" class="card cart-box">
				<view class="head-box">
					<view class="order">
						运单号：<text class="number">{{ item.jijiancg }}</text>
					</view>
					<view class="copy">
						复制
					</view>
				</view>
				<view class="info-box">
					<view class="sending">
						<view class="from-to">
							<view class="area">
								{{ item.facity }}
							</view>
							<view class="name">
								{{ item.fuser }} {{item.jmobile}}
							</view>
						</view>
						<view class="status">
							<image class="right" src="/static/index/right.png"></image>
						</view>
						<view class="from-to">
							<view class="area">
								{{ item.shoucity }}
							</view>
							<view class="name">
								{{ item.suser }} {{item.smobile}}
							</view>
						</view>
					</view>
					<view class="list">
						<view class="list-item">
							系统单号：{{ item.order_sn }} <text>复制</text>
						</view>
						<view class="list-item">
							下单时间：{{ item.create_time_text }}
						</view>
					</view>
				</view>
				<view class="foot-box">
					<view class="button" @click="onDelete(item.id)">
						删除订单
					</view>
				</view>
			</view>
		</view>
	</s-layout>
</template>

<script setup>
	import { ref, reactive } from 'vue'
	import sheep from '@/sheep';
  import { onShow } from '@dcloudio/uni-app';
	
	const tabs = reactive([
		{
			title: '寄',
			number: 0,
			type: 1
		},
		{
			title: '收',
			number: 0,
			type: 2
		}
	])
	const current = ref(1)
	const list = ref([])
	const popup = ref()
	
	const onClick = (type) => {
		current.value = type
		getData()
	}
	
	const onDelete = (id) => {
		uni.showModal({
		  title: '提示',
		  content: '确认删除吗？',
		  success: async function (res) {
				if (res.confirm) {
					const { code } = await sheep.$api.order.deleteItem(id)
					if (code === 1) {
					  getData()
					}
				}
		  },
		});
	}
	
	const getData = async () => {
		const { data } = await sheep.$api.order.list({
			status: 'all',
			type: current.value
		})
		list.value = data.data
		tabs[current.value - 1].number = data.data.length
	}
	
	onShow(() =>{
		getData()
	})
</script>

<style lang="scss" scoped>
	.head-box {
		background-color: #fff;
		.search-box {
			padding: 60rpx 30rpx 20rpx;
			.search-content {
				display: flex;
				align-items: center;
				height: 80rpx;
				padding: 0 30rpx;
				background-color: #f2f4f8;
				border-radius: 80rpx;
				column-gap: 24rpx;
				.search-icon {
					font-size: 42rpx;
					color: #000;
				}
				.search-input {
					font-size: 30rpx;
					color: #000;
					flex: 1;
				}
			}
		}
		.tabs-box {
			display: flex;
			height: 120rpx;
			line-height: 120rpx;
			.tab {
				width: 240rpx;
				font-size: 30rpx;
				color: #000;
				text-align: center;
				&.active {
					color: #ff9966;
					font-weight: 600;
					border-bottom: 6rpx solid #ff9966;
				}
			}
		}
	}
	.container {
		padding: 20rpx;
		.cart-box {
			overflow: hidden;
			&:not(:first-child) {
				margin-top: 20rpx;
			}
			.head-box {
				display: flex;
				align-items: center;
				padding: 30rpx 20rpx;
				font-size: 30rpx;
				column-gap: 20rpx;
				border-bottom: 2rpx solid #eeeeee;
				.order {
					color: #2c2c2c;
					.number {
						color: #ff6600;
					}
				}
				.copy {
					color: #999999;
					font-size: 24rpx;
				}
			}
			.info-box {
				display: flex;
				flex-direction: column;
				row-gap: 40rpx;
				padding: 10rpx 30rpx;
				.sending {
					display: flex;
					justify-content: space-around;
					align-items: center;
					column-gap: 20rpx;
					margin-top: 20rpx;
					.from-to {
						display: flex;
						flex-direction: column;
						align-items: center;
						row-gap: 12rpx;
						.area {
							font-size: 38rpx;
							color: #2c2c2c;
							font-weight: 600;
						}
						.name {
							max-width: 240rpx;
							color: #999999;
							font-size: 24rpx;
							word-break: break-word;
							text-align: center;
						}
					}
					.status {
						display: flex;
						flex-direction: column;
						align-items: center;
						.right {
							width: 120rpx;
							height: 80rpx;
						}
					}
				}
				.list {
					&-item {
						padding: 8rpx 0;
						color: #999999;
					}
				}
			}
			.foot-box {
				display: flex;
				justify-content: flex-end;
				column-gap: 20rpx;
				padding: 20rpx;
				.button {
					width: 180rpx;
					height: 68rpx;
					line-height: 68rpx;
					text-align: center;
					color: #000000;
					background-color: #f5f5f5;
					font-size: 30rpx;
					border-radius: 34rpx;
				}
			}
		}
	}
</style>